package com.example.backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.backend.entity.PingJia;
import com.example.backend.entity.vo.SJPLQ;
import com.example.backend.mapper.PingJiaMapper;
import com.example.backend.service.IPingJiaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class PingJiaService implements IPingJiaService {
    @Autowired
    private PingJiaMapper pingJiaMapper;
    @Override
    public boolean addPingJia(PingJia pingJia) {
        return pingJiaMapper.insert(pingJia) > 0;
    }

    @Override
    public boolean deletePingJia(Integer pjid) {
        return pingJiaMapper.deleteById(pjid) > 0;
    }

    @Override
    public PingJia queryPingJia(Integer pjid) {
        return pingJiaMapper.selectById(pjid);
    }

    @Override
    public List<PingJia> queryPingJiaList() {
        return pingJiaMapper.selectList(null);
    }

    @Override
    public Double getAVGPinFen(Integer sjid) {
        return pingJiaMapper.getAVGPinFen(sjid);
    }

    @Override
    public List<PingJia> getPinJias(Integer sjid) {
        return pingJiaMapper.getPinJias(sjid);
    }

    public HashMap<String,Object> getAllPingJiaAnalysis() {
        HashMap<String,Object> map = new HashMap<>();
        //用户类型
        map.put("userType",pingJiaMapper.getUserType());
        //评分类型 数量
        map.put("pingFenType",pingJiaMapper.getPingFen());
        return map;
    }

    @Override
    public HashMap<String,Object> getSJPingJiaAnalysis(Integer sjid) {
        HashMap<String,Object> map = new HashMap<>();
        //商家评分类型 数量
        map.put("SJpingFenType",pingJiaMapper.getPingFenBySjid(sjid));
        System.out.println(map);
        return map;
    }

    @Override
    public List<PingJia> queryPingJiaByYhid(Integer yhid) {
        return pingJiaMapper.selectList(new QueryWrapper<PingJia>().eq("yhid",yhid));
    }

    @Override
    public List<SJPLQ> getSJPLQ(Integer sjid) {
        return pingJiaMapper.getSJPLQ(sjid);
    }

    @Override
    public boolean updatePingJia(PingJia pingJia) {
        return pingJiaMapper.updateById(pingJia) > 0;
    }

}
